package cn.com.ieds.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbUtil {
    private DbUtil(){}

    private static DbUtil instance = new DbUtil();
    private Connection connection;

    public static DbUtil getInstace() {
        return instance;
    }

    //注册驱动
    static {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    public Connection getConnection(){
        try {
            connection = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/authority_management?useUnicode=true&characterEncoding=utf8",
                    "root",
                    "123456");
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return connection;
    }

    public void close(){
        try {
            connection.close();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


}
